#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import locale
import re
import datetime
import time
import csaldo
import core

locale.setlocale(locale.LC_ALL, 'pt_BR.UTF-8')
conf_dir = os.path.expanduser('~/.personal-finances')
os.chdir(conf_dir)

class InsereDespesa:

        def idespesa(self):
	
		os.system('clear')
		dia = datetime.date.today()
		valord = float(raw_input('\t\tINFORME O VALOR DA DESPESA: '))
		descd = raw_input('\t\tINFORME A DESCRIÇÃO DA DESPESA: ')
		print '\t\tCONFIRMA O VALOR', locale.currency(valord),'DA DESPESA REFERENTE A ',descd,'\n'
		yesno = raw_input('\t\t(S) SIM\t(N)NÃO: ')
		analisa = re.compile('[sSyY]')
		
		if analisa.match(yesno):
			fd = open('despesas','a')
			fd.write("%s\t%.2f\t%s\n" % (dia, valord, descd))
			fd.close()
			totald = 0
			for i in file('despesas'):
				dia, valord, descd = i.split('\t')
				totald += float(valord)
				fdt = open('total-despesas','w')
				fdt.write('%.2f\n' % (totald))
				fdt.close()
			csa = csaldo.ConsultaSaldo()
			csa.csaldo()
		else:
			fn = core.FinancesCore()
			fn.main()
